Adding a Field to a Widget

This section provides an example of adding a Content type drop down to the List Summary widget. The drop down lets the person dropping the widget on the page select from these choices.

Here is what the drop down looks like once it is implemented.

Show me.

To add this drop down to the List Summary widget, follow these steps.

  1. In Visual Studio, open the ListSummary widget, site root/widgets/ListSummary.ascx.
  2. Find the text DisplaySelectedContent.
  3. Below DisplaySelectedContent, add the following code to create a drop down list for the ContentType property.
    Show me.
    <tr>
    <td>
    DisplaySelectedContent:</td>
    <td>
    <asp:CheckBox ID="DisplaySelectedContentCheckBox" runat="server" />
    </td>
    </tr>
    <tr>
    <td>
    ContentType:
    </td>
    <td>
    <asp:DropDownList ID="ContentTypeList" runat="server">
    <asp:ListItem Value="AllTypes">AllTypes</asp:ListItem>
    <asp:ListItem Value="Content">Content</asp:ListItem>
    <asp:ListItem Value="Assets">Assets</asp:ListItem>
    </asp:DropDownList>
    </td>
    </tr>
  4. Save the ListSummary.ascx file.
  5. Open the codebehind file, ListSummary.ascx.cs.
  6. In the properties region, declare a string variable for the ContentType property, as shown below.

    private string _ContentType;

  7. Create a local property with default setting of AllTypes, as shown below.

    [WidgetDataMember("AllTypes")]

    public string ContentType { get { return _ContentType; } set { _ContentType = value; } }

  8. In the EditEvent area, set the select list's value to ContentType.

    ContentTypeList.SelectedValue = ContentType;

  9. In the SaveButton_Click event, set ContentType as the select list's value.

    ContentType = ContentTypeList.SelectedValue;

  10. In the SetListSummary() function, set the List Summary server control's ContentType to the CMSContentType property.

    ListSummary1.ContentType = (CMSContentType)Enum.Parse(typeof(CMSContentType), ContentType);

  11. Save the ListSummary.ascx.cs file.
Previous TopicNext Topic|